package com.junchenrobot.mes.core;

import com.junchenrobot.mes.dao.WinderTaskRunDao;
import com.junchenrobot.mes.domain.FindDevice;
import com.junchenrobot.mes.domain.WinderTask;
import com.junchenrobot.mes.domain.WinderTaskRun;
import com.junchenrobot.mes.domain.WinderTaskSpare;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
public class aaa {
    @Autowired
    WinderTaskRunDao winderTaskRunDao;
    public static void main(String[] args) throws InterruptedException {
        for (int i=0;i<1000;i++){
            System.out.println(i);
            System.out.println("=========");
            //TimeUnit.SECONDS.sleep(3);
            Thread threadOne = new Thread(new Runnable() {
                int a =0;
                @SneakyThrows
                public void run() {
                    System.out.println(111);
                    //Thread.sleep(2000);
                    a = a + 2;
                    System.out.println(12);
                }
            });
            threadOne.start();

        }

//        List<Integer> list= new ArrayList<>();
//        Integer integer = list.get(0);
//        System.out.println(integer);
//        LocalDateTime time1 = LocalDateTime.now().plusMinutes(1);
//        LocalDateTime time2 = LocalDateTime.now().plusMinutes(2);
//        LocalDateTime time3 = LocalDateTime.now().plusMinutes(3);
//        LocalDateTime time4 = LocalDateTime.now().plusMinutes(4);
//        LocalDateTime time = LocalDateTime.now();
//        System.out.println(time);
//        LocalDateTime time1 = LocalDateTime.now();
//        if (time1.isBefore(time)){
//            System.out.println(11);
//        }else{
//            System.out.println(22);
//        }
//        System.out.println(time1.isBefore(time));
//        List<LocalDateTime> a = new ArrayList<>();
//        a.add(time);
//        a.add(time1);
//        a.add(time2);
//        a.add(time3);
//        a.add(time4);
//        System.out.println(a);
//        List<LocalDateTime> collect = a.stream().filter(b -> b.isBefore(time2))
//                .collect(Collectors.toList());
//        System.out.println(collect);
//        System.out.println(Instant.now().toEpochMilli());
//        System.out.println(new Random().nextInt(10000));


//        FindDevice findDevice = new FindDevice();
//        findDevice.setDevicePole(1);
//        findDevice.setDeviceName("1");
//
//        LocalDateTime dateTime = LocalDateTime.of(2023,02,14,20,51,05);
//        LocalDateTime dateTime1 = LocalDateTime.of(2023,02,14,20,51,05);
//        LocalDateTime dateTime2 = LocalDateTime.of(2023,02,17,20,51,05);
//        LocalDateTime dateTime3 = LocalDateTime.of(2023,02,17,20,40,05);
//        LocalDateTime time = LocalDateTime.now().plusMinutes(2);
//        LocalDateTime dateTime = LocalDateTime.now().plusDays(-1);
//        System.out.println(dateTime);
//        double a = 0.140000;
//
//
//        if (a==new Double(0.14)){
//            System.out.println(111);
//        }else{
//            System.out.println(222);
//        }


//        List<WinderTaskSpare> collect = new LinkedList<>();
//        WinderTaskSpare winderTaskSpare = WinderTaskSpare.builder()
//                .taskWarnTime(dateTime).build();
//        collect.add(winderTaskSpare);
//        WinderTaskSpare winderTaskSpare1 = WinderTaskSpare.builder()
//                .taskWarnTime(dateTime1).build();
//        collect.add(winderTaskSpare1);
//        WinderTaskSpare winderTaskSpare2 = WinderTaskSpare.builder()
//                .taskWarnTime(dateTime2).build();
//        collect.add(winderTaskSpare2);
//        WinderTaskSpare winderTaskSpare3 = WinderTaskSpare.builder()
//                .taskWarnTime(dateTime3).build();
//        collect.add(winderTaskSpare3);
//
//        List<WinderTaskSpare> winderTaskSpareList = collect.stream()
//                .filter(b ->b.getTaskWarnTime().isBefore(time))
//                .collect(Collectors.toList());
//        System.out.println(winderTaskSpareList.size());
//
//        for (WinderTaskSpare winderTaskSpare4:winderTaskSpareList){
//            System.out.println(winderTaskSpare4);
//        }
//        boolean before = dateTime3.isBefore(time);
//        System.out.println(before);
//        System.out.println(time);

//        System.out.println(Objects.isNull(findDevice.getDeviceName())&&Objects.isNull(findDevice.getDevicePole()));
//        WinderTaskRunDao winderTaskRunDao;
//            WinderTaskRun winderTaskRun = WinderTaskRun.builder()
//                    .taskDeviceName("111").build();

    }
//    public static void main(String[] args) {
//       TaskStored taskStored = new TaskStored();
//       WinderTask winderTask = WinderTask.builder()
//               .taskWinderLine(2)
//               .taskWinderSpinningCode(15).build();
//        WinderTask winderTask1 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(14).build();
//        WinderTask winderTask2 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(5).build();
//        WinderTask winderTask3 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(20).build();
//        List<WinderTask> list = new ArrayList<>();
//        list.add(winderTask);
//        list.add(winderTask1);
//        list.add(winderTask2);
//        list.add(winderTask3);
//        System.out.println(list.size());
//        for (WinderTask winderTask4:list){
//            System.out.println(winderTask4);
//        }
//        if (list.size()>0) {
//            taskStored.getWinderTask(list);
//        }
//    }
//}
}

class b {
    private int a = 0;
    private int b = 0;

    private int aVoid() {
        Thread threadOne = new Thread(new Runnable() {
            @SneakyThrows
            public void run() {
                System.out.println(111);
                Thread.sleep(2000);
                a = a + 2;
                System.out.println(12);
            }
        });
        if (b == 0) {
            Thread threadTwo = new Thread(new Runnable() {
                @SneakyThrows
                public void run() {
                    System.out.println(222);
                    b = 2;
                    Thread.sleep(6000);
                    System.out.println(15);

                }
            });
            threadOne.start();
//            threadTwo.start();
            try {
                threadOne.join();
                threadTwo.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return b+a;
        }

        // 执行线程
        threadOne.start();
        try {
            threadOne.join();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return b+a;
    }


    public static void methodOne() {
        System.out.println(127);

        System.out.println("Method one is running!");
    }

    public static void methodTwo() {
        System.out.println(128);
        System.out.println("Method two is running!");
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//

//        Double d = 0.85900001525878911;
//        String  str22 = String.format("%.2f",d);
//        System.out.println(str22);
//

//        String a = "1";
//        String b = "2";
//        String c = "3";
//        String d = "4";
//
//        List<String> lastOutputTask1 = new LinkedList<>();
//        lastOutputTask1.add(a);
//        lastOutputTask1.add(b);
//        lastOutputTask1.add(c);
//        lastOutputTask1.add(d);
//        for (String s : lastOutputTask1) {
//            System.out.println(s);
//            CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println(111);
//            try {
//                Thread.sleep( 5000 );
//            } catch (Exception e){
//                System.exit( 0 ); //退出程序
//            }
//            System.out.println(222);
//            });
//            System.out.println("结果:" +  completableFuture.get());
//        }

//        WinderTaskSpare winderTaskSpare = WinderTaskSpare.builder()
//                .taskDeviceName("1").build();
//        List<WinderTaskSpare> collect = new LinkedList<>();
//        collect.add(winderTaskSpare);
//
//        WinderTaskRun winderTaskRun = WinderTaskRun.builder().build();
//        winderTaskRun.setTaskDeviceName("2");
//        List<WinderTaskRun> winderTaskRuns =new LinkedList<>();
//        winderTaskRuns.add(winderTaskRun);
//        System.out.println(winderTaskRuns.size());
//        List<WinderTaskSpare> winderTaskSpareList= collect.stream()
//                .filter(Objects::nonNull)
//                .filter(a -> winderTaskRuns.stream()
//                        .filter(Objects::nonNull)
//                        .noneMatch(id -> Objects.equals(a.getTaskDeviceName(), id.getTaskDeviceName())))
//                .collect(Collectors.toList());
//        System.out.println(winderTaskSpareList.size());
//        WinderTask winderTask = WinderTask.builder().taskDeviceName("1").build();
//WinderTaskSpare winderTaskSpare = new WinderTaskSpare();
//        BeanUtils.copyProperties(winderTask,winderTaskSpare);
//        System.out.println(winderTaskSpare);
//        JSONObject jsonObject = (JSONObject) JSON.parse(winder);
//        WinderTaskSpare winderTaskSpare =JSONObject.toJavaObject(jsonObject,WinderTaskSpare.class);
//        System.out.println(winderTaskSpare);


//        WinderTask winderTask = WinderTask.builder()
//                .taskDeviceName("1").build();
//        List<WinderTask>list = new LinkedList<>();
//      list.add(winderTask);
//      LocalDateTime dateTime =LocalDateTime.now() ;
//      List<WinderTaskSpare> list1 = list.stream().map(v -> WinderTaskSpare.builder()
//              .taskCode(TaskCodeUtil.createTaskCode())
//              .taskDeviceId(1L)
//              .taskType(1)
//              .taskWinderLine(1)
//              .taskWinderId(12L)
//              .taskWinderLsh("24")
//              .taskWinderSpinningCode(54)
//              .taskExecuteStatus(-1)
//              .taskWarnTime(dateTime)
//              .build())
//              .collect(Collectors.toList());
//        System.out.println(list1.get(0));


//        TaskScheduled taskScheduled = new TaskScheduled(null,null,null,null,null,null);
//
//        WinderTask winderTask = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(15).build();
//        WinderTask winderTask1 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(14).build();
//        WinderTask winderTask2 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(5).build();
//        WinderTask winderTask3 = WinderTask.builder()
//                .taskWinderLine(2)
//                .taskWinderSpinningCode(20).build();
//        List<WinderTask> list = new ArrayList<>();
//        list.add(winderTask);
//        list.add(winderTask1);
//        list.add(winderTask2);
//        list.add(winderTask3);
//        System.out.println(list.size());
//        for (WinderTask winderTask4:list){
//            System.out.println(winderTask4);
//        }
//        if (list.size()>0) {
//            taskScheduled.rightStickTask(1,list);
//        }
    }
}


